package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

/**
 * @Description 预约设置控制
 * @Author makun
 * @Date 2023/9/15 15:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {
    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * 编辑某天的预约设置
     * @param orderSetting
     * @return
     */
    @PutMapping
    public Result editNumber(@RequestBody OrderSetting orderSetting) {
        return orderSettingService.editNumberByDate(orderSetting) ? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 批量上传预约设置
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result uploadExcel(MultipartFile file) {
        return orderSettingService.upload(file) ? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 根据年月份获取预约设置情况
     * @param year
     * @param month
     * @return
     */
    @GetMapping
    public Result getOrderSettingByYearMonth(Integer year, Integer month) {
        List<OrderSetting> orderSettings = orderSettingService.getOrderSettingByYearMonth(year, month);
        return Result.buildSuccess(orderSettings);
    }
}
